from langchain_core.tools import tool, StructuredTool
from pydantic import BaseModel, Field

import asyncio


class MultyTypeInput(BaseModel):
    a: int = Field(description="第一个参数")
    b: int = Field(description="第二个参数")

def multiply(a:int,b:int)->int:
    """同步将两个参数相乘"""
    print("同步方法")
    return a*b

async def amultiply(a:int,b:int)->int:
    """异步将两个参数相乘"""
    print("异步方法")
    return a*b

caculator = StructuredTool.from_function(
    func=multiply,
    coroutine=amultiply,
    name="multiply_tools",
    description="用于将两个参数相乘",
    return_direct=True,
    arges_schema=MultyTypeInput
)

print("函数名称",caculator.name)
print("函数描述",caculator.description)
print("函数参数",caculator.args)
print("是否直接返回",caculator.return_direct)

print(caculator.invoke({"a":7,"b":8}))

print(asyncio.run(caculator.ainvoke({"a":5,"b":8})))